home *** CD-ROM | disk | FTP | other *** search
- //: C02:Fillvector.cpp
- // From Thinking in C++, 2nd Edition
- // Available at http://www.BruceEckel.com
- // (c) Bruce Eckel 1999
- // Copyright notice in Copyright.txt
- // Copy an entire file into a vector of string
- #include <string>
- #include <iostream>
- #include <fstream>
- #include <vector>
- using namespace std;
-
- int main() {
- vector<string> v;
- ifstream in("Fillvector.cpp");
- string line;
- while(getline(in, line))
- v.push_back(line); // Add the line to the end
- // Add line numbers:
- for(int i = 0; i < v.size(); i++)
- cout << i << ": " << v[i] << endl;
- } ///:~
-